package com.uh.calculation.operator;


import com.uh.calculation.bean.*;
import com.uh.calculation.util.FormulaUtil;
import com.uh.calculation.util.GetBean;
import com.uh.calculation.util.GetFileds;
import com.uh.calculation.util.TimeUtil;
import com.uh.microservice.core.dao.JdbcDao;
import lombok.Data;
import org.apache.commons.lang.StringUtils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 季报字段--月报字段匹配  逻辑为月报数据/季报数据
 */
@Data
public class JtYOperator {
    private JdbcDao jdbcDao;
    private WarnJiSuanBean warnJiSuanBean;



    public  JtYOperator(JdbcDao jdbcDao,WarnJiSuanBean warnJiSuanBean){
        this.jdbcDao=jdbcDao;
        this.warnJiSuanBean=warnJiSuanBean;

    }


    /**
     * 季报数据
     * 月报数据
     * @param jb
     * @param list
     * @return
     */
    public   void jisuan(List<Map<String, Object>> jb ,List<Map<String, Object>> yb , List<OperatorVal> list ){
        if(jb == null || yb == null || jb.size() == 0 || yb.size() == 0){
            return;
        }
        this.warnJiSuanBean=warnJiSuanBean;
        Date lastTime = warnJiSuanBean.getLastTime();
        //反转2021 与 2022字段区别
        //GetFileds getFileds = new GetFileds(jdbcDao,list,warnJiSuanBean);
        for(OperatorVal operatorVal :list){
            List<FormulaBean> formulaBeans = operatorVal.getFormulaBeans();//计算公式
            String   field = operatorVal.getField();
            List<TbFeild> tbFeilds = GetBean.getTbf(field);
            String  fy = tbFeilds.get(0).getFieldName();
            String  fj = tbFeilds.get(1).getFieldName();
            for(Map m:jb){
                String  timeCode = m.get("time_code").toString();

                //从季报去比较月报
                for(Map my:yb){
                    try {
                        String time = my.get("time_code").toString();
                        if (timeCode.equals(time)) {
                            //时间游标判断，及核查规则是否符合
                            if(TimeUtil.bj(lastTime,timeCode,warnJiSuanBean.getYear_is_month(),warnJiSuanBean.getIs_hc())) {
                                //取月报数据
                                String d1 = m.get(fj).toString();
                                //取季报数据
                                String d2 = my.get(fy).toString();
                                //根据当前计算类解析规则  将数据和字段对应
                                tbFeilds.get(0).setData(d2);
                                tbFeilds.get(1).setData(d1);
                                //扔进公式解析工具
                                new FormulaUtil(tbFeilds, formulaBeans, warnJiSuanBean, operatorVal.getDimension(), timeCode);
                            }

                        }
                    } catch (Exception E) {

                    }
                }
            }
        }
    }
}